<?php
  /**
   * iJAdminsControl
   *
   * The iJAdminsControl class 
   *
   * @copyright Copyright (c) 2011, iJBloks Progect
   */
    class AdminsControl extends iJBlock{
        
        /**
         *
         * Class Constructuctor
         * @access public
         */
        public function __construct() {
    
        }
        
        
        /**
         * execute
         *
         * Executes the block to generate the tokens
         *
         * @return array Array with the tokens of the block
         *
         * @access public
         */
        public function execute() {
          $iJAdmin     =  iJFactory::singleton('iJAdmin');
          $iJLanguages =  iJFactory::singleton('iJLanguages');
          
          if(isset($_POST['create'])) {
            $iJAdmin->register($_POST);
          }
          
          if(isset($_POST['edit'])) {
            $iJAdmin->edit($_POST);
          }
          
          if(isset($_GET['delID'])) {
            $iJAdmin->removeAdmin($_GET['delID']);
          }
          
          $page   = isset($_REQUEST['page'])                                     ? $_REQUEST['page']    : 1;
          $search = isset($_REQUEST['search'])    && !empty($_REQUEST['search']) ? $_REQUEST['search']  : '';
          $admList = $iJAdmin->getAdministratorsList($page, $search);
          
          $list       = $admList[0];
          $QAdmins    = $admList[1];
          
          
          $this->addToken('list',        $list);         
          $this->addToken('search',      $search);
          $this->addToken('page',        $page);


          $this->addToken('admin_icon',  iJHrefLink::Icon('user', '16x16'));
          $this->addToken('delete_icon', iJHrefLink::Icon('trash', '16x16'));
          $this->addToken('edit_icon',   iJHrefLink::Icon('edit', '16x16'));
          $this->addToken('info_icon',   iJHrefLink::Icon('info', '16x16'));
          
          $this->addToken('form_action', iJHrefLink::linkToLocalPage('admin_control')); 
          $this->addToken('curLanguage', $iJLanguages->getLanguage());
          $this->addToken('languages',   $iJLanguages->getLanguagesExeptCurrent());  
          
          $this->addToken('total_items',    $QAdmins->getSize());
          $this->addToken('pages_count',    $QAdmins->getPagesCount());
          $this->addToken('prev_link',      $QAdmins->getPerviousLink($page, 'admin_control'));
          $this->addToken('next_link',      $QAdmins->getNextLink($page,     'admin_control'));
          
          return parent::execute();
        }
        
    }
?>